﻿using System;
using UnityEngine;

namespace Core
{
    [CreateAssetMenu(menuName = "Mini/Sys/Conf/Language")]
    public class TblLanguage : AbstractSOTable<string, TblLanguage.Conf>
    {
        [Serializable]
        public class Conf : ITableConf<string>
        {
            public string Index => Key;

            public string Key;
            public string ChineseSimplified;
            public string ChineseTraditional;
            public string English;
            public string Japanese;
            public string Korean;

            public void Awake() { }
        }

        /// <summary>
        /// 翻译
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        public string Translate(string text)
        {
            var lang = Context.Sys.Setting.Language.Curr;
            var conf = Find(text);
            if (conf == null)
            {
                return $"【{text}】";
            }

            switch (lang)
            {
                case SystemLanguage.Chinese:
                case SystemLanguage.ChineseSimplified:
                    return conf.ChineseSimplified;
                case SystemLanguage.ChineseTraditional:
                    return conf.ChineseTraditional;
                case SystemLanguage.English:
                    return conf.English;
                case SystemLanguage.Japanese:
                    return conf.Japanese;
                case SystemLanguage.Korean:
                    return conf.Korean;
                default:
                    return conf.English;
            }

        }
    }
}
